<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_UpFile.asp
'= 摘    要：后台-上传文件管理文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2005-10-16
'====================================================================

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"61") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim  Atcion,sFor(31,1)
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case Else
	Call Main()
End Select
Set Rs=Nothing
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing
	
Sub Main()
	Dim path
	Dim mainpath
	Dim requestpath
	Dim ParentFolder
	Dim objFSO
	Dim uploadfolder,uploadChildFolder
	Dim uploadfiles
	Dim upname
	Dim UpFolder
	Dim i
	Dim pagesize, page, filenum, pagenum
	Dim FieldName(1),FieldValue(1)
	Dim ListBlock,Temp

	sFor(0,0)="txt":sFor(0,1)="txt"
	sFor(1,0)="chm":sFor(1,1)="chm"
	sFor(2,0)="hlp":sFor(2,1)="chm"
	sFor(3,0)="doc":sFor(3,1)="doc"
	sFor(4,0)="pdf":sFor(4,1)="pdf"
	sFor(5,0)="gif":sFor(5,1)="gif"
	sFor(6,0)="jpg":sFor(6,1)="jpg"
	sFor(7,0)="png":sFor(7,1)="png"
	sFor(8,0)="bmp":sFor(8,1)="bmp"
	sFor(9,0)="asp":sFor(9,1)="asp"
	sFor(10,0)="jsp":sFor(10,1)="asp"
	sFor(11,0)="js" :sFor(11,1)="asp"
	sFor(12,0)="htm":sFor(12,1)="html"
	sFor(13,0)="html":sFor(13,1)="html"
	sFor(14,0)="shtml":sFor(14,1)="html"
	sFor(15,0)="zip":sFor(15,1)="zip"
	sFor(16,0)="rar":sFor(16,1)="rar"
	sFor(17,0)="exe":sFor(17,1)="exe"
	sFor(18,0)="avi":sFor(18,1)="avi"
	sFor(19,0)="mpg":sFor(19,1)="mpg"
	sFor(20,0)="ra" :sFor(20,1)="ra"
	sFor(21,0)="ram":sFor(21,1)="ra"
	sFor(22,0)="mid":sFor(22,1)="mid"
	sFor(23,0)="wav":sFor(23,1)="wav"
	sFor(24,0)="mp3":sFor(24,1)="mp3"
	sFor(25,0)="asf":sFor(25,1)="asf"
	sFor(26,0)="php":sFor(26,1)="aspx"
	sFor(27,0)="php3":sFor(27,1)="aspx"
	sFor(28,0)="aspx":sFor(28,1)="aspx"
	sFor(29,0)="xls":sFor(29,1)="xls"
	sFor(30,0)="mdb":sFor(30,1)="mdb"

	path="../UserFiles"
	mainpath=server.MapPath (path)
	requestpath=request.QueryString ("path")

	if requestpath<>"" then	
		requestpath=Replace(requestpath,"..","")
		path=path&requestpath
	end if

	pagesize=20
	page=request.querystring("page")
	if page="" or not isnumeric(page) then
		page=1
	else
		page=int(page)
	end if
	on error resume next

	PageContent=Template.LoadTemplate("admin_upfile_list.htm")

	
	Template.SetVariable "Language_Comm_ListEmpty",str_Comm_ListEmpty,PageContent
	Template.SetVariable "Language_Comm_Bar_Operation",str_Comm_Bar_Operation,PageContent
	Template.SetVariable "Language_Comm_Edit_Operation",str_Comm_Edit_Operation,PageContent
	Template.SetVariable "Language_Comm_Alert_Del_Operation",str_Comm_Alert_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Del_Operation",str_Comm_Del_Operation,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_UpFile_Help",str_UpFile_Help,PageContent

	Template.SetVariable "Language_UpFile_Type",str_UpFile_Type,PageContent
	Template.SetVariable "Language_UpFile_FileName",str_UpFile_FileName,PageContent
	Template.SetVariable "Language_UpFile_Size",str_UpFile_Size,PageContent
	Template.SetVariable "Language_UpFile_LastTime",str_UpFile_LastTime,PageContent
	Template.SetVariable "Language_UpFile_UploadTime",str_UpFile_UploadTime,PageContent
	Template.SetVariable "Language_UpFile_CurrentPath",str_UpFile_CurrentPath,PageContent

	Template.SetVariable "Path",path,PageContent
	Template.SetVariable "RequsetPath",request("path"),PageContent

	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

	if request("filename")<>"" then
	   if objFSO.fileExists(Server.MapPath(""&path&"\"&request("filename"))) then
			objFSO.DeleteFile(Server.MapPath(""&path&"\"&request("filename")))
	   end if
	end if

	Set uploadFolder=objFSO.GetFolder(Server.MapPath(""&path&"\"))

	if err.number<>0 then
		ErrMsg = Err.Description
		Call EA_Manager.Error(1)
	end if

	ParentFolder=objFSO.GetParentFolderName(Server.MapPath(""&path&"\"))
	ParentFolder=Replace(ParentFolder,mainpath,"",1,-1,1)
	ParentFolder=Replace(ParentFolder,"\","/",1,-1,1)
	Template.SetVariable "ParentFolder",ParentFolder,PageContent


	Set uploadChildFolder=uploadFolder.SubFolders 
	ListBlock=Template.GetBlock("folderlist",PageContent)
	For Each Upname In uploadChildFolder
		Temp=ListBlock

		Template.SetVariable "RequestPath",requestpath,Temp
		Template.SetVariable "FolderName",Upname.name,Temp

		Template.SetBlock "folderlist",Temp,PageContent
	Next
	Template.CloseBlock "folderlist",PageContent


	Set uploadFiles=uploadFolder.Files
	filenum=uploadfiles.count
	i=0
	ListBlock=Template.GetBlock("list",PageContent)
	For Each Upname In uploadFiles
		i=i+1
		if i>(page-1)*pagesize and i<=page*pagesize then
			Temp=ListBlock
			
			Template.SetVariable "FileExt",procGetFormat(upname.name),Temp
			Template.SetVariable "UpFileName",upname.name,Temp
			Template.SetVariable "UpFileSize",showfilesize(upname.size),Temp
			Template.SetVariable "UpFileLastTime",upname.datelastaccessed,Temp
			Template.SetVariable "UpFileUpLoadTime",upname.datecreated,Temp

			Template.SetBlock "list",Temp,PageContent
		elseif i>page*pagesize then
			exit for
		end if
	next
	Template.CloseBlock "list",PageContent


	set uploadFolder=nothing
	set uploadChildFolder=nothing
	set uploadFiles=nothing
	set objFSO=nothing


	FieldName(0)="path"
	FieldValue(0)=request.QueryString ("path")
	Template.SetVariable "PageListNav",EA_Manager.PageList(pagesize,filenum,Page,FieldName,FieldValue),PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent
end sub

function procGetFormat(sName)
	Dim  i,str
	
	procGetFormat=0
	
	if instrRev(sName,".")=0 then exit function
	
	str=LCase(Mid(sName,instrRev(sName,".")+1))
	
	for i=0 to uBound(sFor,1)
		if str=sFor(i,0) then 
			procGetFormat=sFor(i,1)
			exit for
		end if
	next
end function

function showfilesize(size)
	if size>1024 then
		size=(Size/1024)
		showfilesize=formatnumber(size,2) & "&nbsp;KB"
	end if
	if size>1024 then
		size=(size/1024)
		showfilesize=formatnumber(size,2) & "&nbsp;MB"
	end if
	if size>1024 then
 	   size=(size/1024)
 	   showfilesize=formatnumber(size,2) & "&nbsp;GB"
 	end if 
end function
%>